package com.zhoun.controller.backend;

import com.zhoun.common.ServerResponse;
import com.zhoun.pojo.Product;
import com.zhoun.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/manage/product")
public class ProductManageController {

    @Autowired
    private ProductService productService;

    @RequestMapping("/list")
    @ResponseBody
    public ServerResponse getProductLis(@RequestParam(defaultValue = "1") Integer pageNum,
                                        @RequestParam(defaultValue = "20") Integer pageSize){
        return productService.getProductList(pageNum,pageSize);
    }

    @RequestMapping(value = "/addOrUpdate",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse addOrUpdate(Product product){
        return productService.addOrUpdate(product);
    }

    @RequestMapping("/getProductById")
    @ResponseBody
    public ServerResponse getProductById(Integer productId){
        return productService.getProductById(productId);
    }

    @RequestMapping("/delete")
    @ResponseBody
    public ServerResponse delete(Integer productId){
        return productService.delete(productId);
    }



}
